/**
 * Created by Ji.wenjiang on 2016/9/13.
 */


/**
 * Created by TRwin7SP1 on 2016/8/23.
 */
angular.module('inspinia')
  .controller('CTdirector', function ($scope, $log) {
    $scope.myChart = echarts.init(document.getElementById('main'));
    $scope.myCahrtActual = echarts.init(document.getElementById('actual'));
    $scope.myChartPlan = echarts.init(document.getElementById('plan'));


    // 基于准备好的dom，初始化echarts实例

    // 指定图表的配置项和数据
    var option = {
      title: {
        text: '昨日加速器统计表'
      },
      tooltip: {},
      legend: {
        data: ['计划', '实际']
      },
      xAxis: {
        data: ["1号机", "2号机", "3号机", "4号机", "5号机", "6号机", "7号机", "8号机", "9号机"]
      },
      yAxis: {},
      series: [{
        name: '计划',
        type: 'line',
        data: [5, 20, 36, 10, 10, 20, 45, 8, 41]
      }, {
        name: '实际',
        type: 'bar',
        events: {},
        data: [
          {value: 8, id: 1},
          {value: 18, id: 2},
          {value: 30, id: 3},
          {value: 20, id: 4},
          {value: 15, id: 5},
          {value: 20, id: 6},
          {value: 18, id: 7},
          {value: 30, id: 8},
          {value: 20, id: 9},
        ],
      }]
    };
    $scope.machineNum = 1;
    $scope.chartData1 = [5, 20, 36, 10, 10, 20, 45];
    $scope.chartData2 = [9, 18, 30, 20, 15, 28, 40];
    $scope.chartData3 = [21, 20, 36, 10, 10, 20, 15];
    $scope.chartData4 = [18, 11, 33, 21, 28, 29, 18];

// 指定图表的配置项和数据
    $scope.actualOption = {
      title: {
        text: $scope.machineNum + '号加速器上周实际与计划对比图'
      },
      tooltip: {},
      legend: {
        data: ['计划', '实际']
      },
      xAxis: {
        data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
      },
      yAxis: {},
      series: [{
        name: '计划',
        type: 'line',
        data: $scope.chartData1
      }, {
        name: '实际',
        type: 'bar',
        data: $scope.chartData2
      }]
    };


    // 指定图表的配置项和数据
    $scope.planOption = {
      title: {
        text: $scope.machineNum + '号加速器本周实际与计划对比图'
      },
      tooltip: {},
      legend: {
        data: ['计划', '实际']
      },
      xAxis: {
        data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
      },
      yAxis: {},
      series: [{
        name: '计划',
        type: 'line',
        data: $scope.chartData3
      }, {
        name: '实际',
        type: 'bar',
        data: $scope.chartData4
      }]
    };

    $scope.myChart.setOption(option);
    $scope.myCahrtActual.setOption($scope.actualOption);
    $scope.myChartPlan.setOption($scope.planOption);


    // 使用刚指定的配置项和数据显示图表。


    //添加点击事件
    function chart1() {
      // $log.debug(111);
      $scope.machineNum = 1;
      $scope.chartData1 = [5, 20, 36, 10, 10, 20, 45];
      $scope.chartData2 = [9, 18, 30, 20, 15, 28, 40];
      $scope.chartData3 = [21, 20, 36, 10, 10, 20, 15];
      $scope.chartData4 = [18, 11, 33, 21, 28, 29, 18];
      $scope.actualOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      $scope.planOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      $scope.myCahrtActual.setOption($scope.actualOption);
      $scope.myChartPlan.setOption($scope.planOption);
      $scope.$apply();
    }

    function chart2() {
      $scope.machineNum = 2;
      $scope.chartData1 = [33, 15, 36, 7, 10, 20, 45];
      $scope.chartData2 = [18, 11, 33, 21, 28, 29, 18];
      $scope.chartData3 = [21, 20, 16, 10, 44, 20, 15];
      $scope.chartData4 = [9, 18, 30, 20, 15, 28, 40];
      $scope.actualOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      $scope.planOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      $scope.myCahrtActual.setOption($scope.actualOption);
      $scope.myChartPlan.setOption($scope.planOption);
      $scope.$apply();
      $log.debug(222);
    }

    function chart3() {

      $scope.machineNum = 3;
      $scope.chartData1 = [9, 18, 30, 20, 15, 28, 40];
      $scope.chartData2 = [33, 15, 11, 31, 10, 22, 45];
      $scope.chartData3 = [21, 20, 41, 10, 44, 20, 15];
      $scope.chartData4 = [18, 11, 33, 21, 28, 29, 18];
      $scope.actualOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      $scope.planOption = {
        title: {
          text: $scope.machineNum + '号加速器本周实际与计划对比图'
        },
        tooltip: {},
        legend: {
          data: ['计划', '实际']
        },
        xAxis: {
          data: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期天"]
        },
        yAxis: {},
        series: [{
          name: '计划',
          type: 'line',
          data: $scope.chartData3
        }, {
          name: '实际',
          type: 'bar',
          data: $scope.chartData4
        }]
      };
      // $scope.$apply();
      $scope.myCahrtActual.setOption($scope.actualOption);
      $scope.myChartPlan.setOption($scope.planOption);
      $log.debug(333);
    }

    $scope.myChart.on('click', function (params) {
      switch (params.data.id) {
        case 1:
          chart1();
          break;
        case 2:
          chart2();
          break;
        case 3:
          chart3();
          break;
      }

    })


  });
